#include "./qttest/signal/QtSignal.h"
#include "./qttest/layout/LayoutWindow.h"
#include "./qttest/layout/edit/LineEdit.h"
#include "./qttest/layout/button/Buttons.h"
#include "./qttest/layout/button/ComboBox.h"
#include "./qttest/layout/listview/ListView.h"
#include "./qttest/layout/listview/TreeView.h"
#include "./cantest/cantest.h"
#include "./cantest/open/OpenCan.h"
#include "./cantest/comm/CommunityCan.h"
#include "handler2/Handler2Test.h"

#include "linux/file/file_syscall.h"
#include "linux/file/file_stdio.h"
#include "linux/file/file_dir.h"
#include "linux/file/file_advance.h"
#include "linux/memory/memory_std.h"
#include "linux/cxx/std/container/sequential/ArrayList.h"
#include "linux/cxx/std/container/sequential/LinkedList.h"
#include "linux/cxx/std/container/associative/order/TreeMap.h"
#include "linux/cxx/std/container/associative/order/TreeSet.h"
#include "linux/cxx/std/container/associative/unorder/HashMap.h"
#include "linux/cxx/std/container/associative/unorder/HashSet.h"
#include "linux/cxx/std/container/associative/unorder/HashTable.h"
#include "linux/cxx/std/container/adapters/Stack.h"
#include "linux/cxx/std/container/adapters/Queue.h"
#include "linux/cxx/std/container/adapters/PriorityQueue.h"
#include "linux/cxx/std/algorithm/unmodify/UnmodifySeq.h"
#include "linux/cxx/std/algorithm/modify/ModifySeq.h"
#include "linux/cxx/std/algorithm/findsort/FindSort.h"
#include "linux/cxx/std/algorithm/maxmin/MaxMinValue.h"
#include "linux/cxx/std/iterator/overview/ItrOverview.h"
#include "linux/cxx/std/iterator/itradapter/ItrAdapter.h"
#include "linux/cxx/std/iterator/rangefunc/RangeFunc.h"
#include "linux/cxx/std/iterator/funcobj/FuncObj.h"
#include "linux/cxx/std/iterator/funcadapter/FuncAdapter.h"
#include "linux/cxx/std/memory/pseudocont/PseudoCont.h"
#include "linux/cxx/std/memory/smartptr/SmartPtr.h"
#include "linux/cxx/std/memory/allocator/StdAlloc.h"

#include <QApplication>
#include <QIcon>
#include <iostream>

namespace nsp_class_test {
    class BaseFunc;

    class DerivedFunc;

    int derived_main();
}

int main(int argc, char *argv[]) {
#define CAN     1      // CAN
#define QT_TEST 2      // QT
#define HANDLER 3      // HANDLER
#define LINUX   4      // HANDLER
#define APPLY   LINUX    // 使用的是哪一个功能

#if APPLY == CAN || APPLY == QT_TEST
    QApplication app(argc, argv);
    QIcon qIcon(":/home/pzw/Desktop/Qttest/cantest/res/gcan.ico");
    QApplication::setWindowIcon(qIcon);
#endif

#if APPLY == CAN // 是否是can?
#define RELEASE 1
    if (RELEASE == 1) {// 正式环境，要显示
        OpenCan *openCan = new OpenCan();
        openCan->show();
    } else if (RELEASE == 0) {// 这个界面要独立调整一下，布局有问题
        CommunityCan *communityCan = new CommunityCan();
        communityCan->show();
    } else {
        // 命令行方式打开can
        cantest_main(argc, argv);
    }
    nsp_class_test::derived_main();
#elif APPLY == QT_TEST // QT_TEST
    /**
     * 主界面
     */
    MainWindow w;
    w.show();

    /**
     * qt signal信号测试界面
     */
    QtSignal *qtSignal = new QtSignal();
    qtSignal->show();

    /**
     * 布局界面 - QHBoxLayout
     * 布局界面 - QVBoxLayout
     */
    LayoutWindow *layoutWindow = new LayoutWindow();
    layoutWindow->show();

    /**
     * 构件 - edit
     */
    LineEdit *edit = new LineEdit();
    edit->show();

    /**
    * 构件 - button
    */
    Buttons *buttons = new Buttons();
    buttons->show();

    /**
    * 构件 - 下拉复选框
    */
    ComboBox *cbox = new ComboBox();
    cbox->show();

    /**
    * 构件 - Listview
    */
    ListView *listView = new ListView();
    listView->show();
    TreeView *treeView = new TreeView();
    treeView->show();
#elif APPLY == HANDLER
    return handler2_main(argc, argv);
#elif APPLY == LINUX
    int ret = 7;
    switch (ret) {
        case 0:
            break;
        case 1:
            ret = file_syscall_main();
            break;
        case 2:
            ret = file_stdio_main();
            break;
        case 3:
            ret = file_dir_main();
            break;
        case 4:
            ret = file_advance_fcntl_main();
            break;
        case 5:
            ret = file_advance_mmap_main();
            break;
        case 6:
            ret = memory_std_simple_main();
            break;
        case 7:
            ret = vector_api_main() | list_api_main()
                  | TreeMap_main() | TreeSet_main()
                  | HashMap_main() | HashSet_main() | HashTable_main()
                  | Stack_main() | JavaQueue_main() | JavaPriorityQueue_main()
                  | UnmodifySeq_main() | ModifySeq_main()
                  | FindSort_main() | MaxMinValue_main()
                  | ItrOverview_main() | ItrAdapter_main()
                  | RangeFunc_main() | FuncObj_main()
                  | FuncAdapter_main() | PseudoCont_main()
                  | SmartPtr_main() | StlAllocator_main();
            break;
        default:
            break;
    }
    return ret;
#endif

#if APPLY == CAN || APPLY == QT_TEST
    return QApplication::exec();
#endif
}

/*BaseFunc @{*/
class nsp_class_test::BaseFunc {
public:
    virtual void baseFunc() {
        std::cout << "Base function" << std::endl;
    }

protected:
    int base = 0;
};

class nsp_class_test::DerivedFunc : public nsp_class_test::BaseFunc {
public:
    void derivedFunc() {
        /* 访问基类的成员，可以直接使用::来访问 */
        BaseFunc::baseFunc();
        BaseFunc::base++;
    }

    void baseFunc() override {
        std::cout << "Base func" << std::endl;
    }

};

int nsp_class_test::derived_main() {
    DerivedFunc derived{};
    derived.derivedFunc();
    return 0;
}
/*BaseFunc @}*/